package com.study_security.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.study_security.dto.ProjectDTO;
import com.study_security.dto.ProjectFormDTO;
import com.study_security.dto.TaskDetailDTO;
import com.study_security.entity.Project;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface ProjectMapper extends BaseMapper<Project> {

    List<Project> selectAllProject();
    List<ProjectFormDTO> selectAllProjectFormDTOByUserId(@Param("userId") Long userId);
    List<ProjectFormDTO> selectAllProjectFormDTO();
    List<Project> selectOngoingProjects(@Param("userId") Long userId);

    List<Project> selectCompletedProjects(@Param("userId") Long userId);

   // List<Project> searchOngoingProjects(@Param("userId") Long userId, @Param("keyword") String keyword);
   List<Project> searchOngoingProjects(
           @Param("userId") Long userId,
           @Param("keyword") String keyword,
           @Param("projectType") String projectType,
           @Param("importantLevel") String importantLevel,
           @Param("sortBy") String sortBy
   );

    List<Project> searchCompletedProjects(@Param("userId") Long userId, @Param("keyword") String keyword);

    int insert(Project project);

    int countByProjectName(@Param("projectName") String projectName);

    List<ProjectDTO> selectUserProjects(@Param("userId") Long userId);

    Project selectProjectById(@Param("projectId") Long projectId);

    List<Project> findPendingByName(@Param("name") String name);

    List<Project> findApprovedByName(@Param("name") String name);
    List<Project> findOngoingdByName(@Param("name") String name);

    List<Project> findPending();

    List<Project> findApproved();

    List<Project> findOngoing();


    int updateProjectStatus(@Param("projectId") Long projectId, @Param("status") String status);

    List<Project> getAllProject();

    List<Project> selectAllProjectByUserId(Long userId);

    List<Project> getFilteredProjects(@Param("endDateAfter") String endDateAfter,
                                      @Param("startDateAfter") String startDateAfter,
                                      @Param("contractAmountGt") BigDecimal contractAmountGt);

    List<Project> getFilteredProjectsByUserId(@Param("userId") Long userId,
                                              @Param("endDateAfter") String endDateAfter,
                                              @Param("startDateAfter") String startDateAfter,
                                              @Param("contractAmountGt") BigDecimal contractAmountGt);



    /**
     * 根据项目名称获取项目基本信息
     * @param projectName 项目名称
     * @return Project
     */
    Project getProjectByName(@Param("projectName") String projectName);

    /**
     * 获取项目的所有任务详细信息，包括任务名称、工时、负责人名称、任务开始日期和负责人月薪
     * @param projectName 项目名称
     * @return List<TaskDetailDTO>
     */
    List<TaskDetailDTO> getTasksWithDetailsByProjectName(@Param("projectName") String projectName);
}
